#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

int n, m;
int sx, sy;
string op;
int dis[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
map<PII, bool> ok;

bool dfs(int x, int y, int cnt, vector<vector<int>> &g, vector<vector<bool>> &st){

    st[x][y] = true;
    // cout << "x: " << x << " y: " << y << '\n';

    if(ok.count({x, y})){
        return ok[{x, y}];
    }

    for(int i = 0; i < 4; i ++){
        int nx = x + dis[i][0], ny = y + dis[i][1];

        if(nx < 1 || nx > n || ny < 1 || ny > m) continue;
        if(nx == sx && ny == sy && cnt >= 3){
            ok[{nx, ny}] = true;
            return true;
        }
        if(st[nx][ny]) continue;
        if(g[nx][ny] == 1) continue;
        

        if(dfs(nx, ny, cnt + 1, g, st)){
            ok[{nx, ny}] = true;
            return true;
        }
    }

    ok[{x, y}] = false;
    st[x][y] = false;
    return false;
}

int main(){
#ifdef LOCALFLAG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif


    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;
    vector<vector<int>> g(n + 1, vector<int> (m + 1));
    vector<vector<bool>> st(n + 1, vector<bool> (m + 1, false));
    
    for(int i = 1; i <= n; i ++){
        cin >> op;
        for(int j = 1; j <= m; j ++){ 
            if(op[j - 1] == 'S'){
                g[i][j] = 0;
                sx = i, sy = j;
            }else if(op[j - 1] == '.'){
                g[i][j] = 0;
            }else{  // g[i][j] = #
                g[i][j] = 1;
            }
        }
    }

    bool f = dfs(sx, sy, 0, g, st);

    if(f) cout << "Yes" << '\n';
    else cout << "No" << '\n';






    return 0;
}